//
// Delaunay Triangulation
//
// Homework of CG lesson (Fall 2009) in Tsinghua University.
// All rights reserved.
//

#pragma once

#include <ctime>
#include <cassert>
#include "stdlib.h"
/**
 * The error tolerance used in global scope.
 */
const double TOLERANCE = 0.001;//1e-10;
#define RAND_MAX 0x7fff
/**
 * The max random number.
 */
const double INV_RAND_MAX = 1.0 / (RAND_MAX + 1.0);

/**
 * Returns the absolute value of @c val.
 */
template<typename T>
inline T fabs(T val)
{
    if (val < 0)
        return -val;
    else
        return val;
}

/**
 * Returns the max value of @c val.
 */
template<typename T>
inline T getMax(T a, T b)
{
    if (a > b)
        return a;
    else
        return b;
}

/**
 * Returns the min value of @c val.
 */
template<typename T>
inline T getMin(T a, T b)
{
    if (a > b)
        return b;
    else
        return a;
}

/**
 * Returns a random integer between @c start(inclusive) and @c end(exclusive).
 */
inline int random(int start, int end)
{
    assert(end > start);
    return start + rand() % (end - start);
}

/**
 * Returns a random double double number between 0(inclusive) and 1(exclusive).
 */
inline double random(void)
{
    return  rand() * INV_RAND_MAX;
}
